package com.rongke.web.controller.dict;

import java.util.List;

import com.rongke.commons.JsonResp;
import com.rongke.model.dict.DictInspection;
import com.rongke.model.dict.DictMedicine;
import com.rongke.model.dict.DictMedicineType;
import com.rongke.model.dict.DictMedicineUseType;
import com.rongke.model.dict.DictOperation;
import com.rongke.model.dict.DictOperationType;
import com.rongke.service.DictInspectionService;
import com.rongke.service.DictMedicineService;
import com.rongke.service.DictMedicineTypeService;
import com.rongke.service.DictMedicineUseTypeService;
import com.rongke.service.DictOperationService;
import com.rongke.service.DictOperationTypeService;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 查询各类字典信息
 */
@RestController
@RequestMapping(value = "/api/dict")
@Transactional
public class DictController {
    private static final Logger        log = Logger.getLogger(DictController.class);
    @Autowired
    private DictInspectionService      dictInspectionService;

    @Autowired
    private DictMedicineService        dictMedicineService;

    @Autowired
    private DictMedicineUseTypeService dictMedicineUseTypeService;

    @Autowired
    private DictOperationService       dictOperationService;

    @Autowired
    private DictOperationTypeService   dictOperationTypeService;

    @Autowired
    private DictMedicineTypeService    dictMedicineTypeService;

    @RequestMapping(value = "/queryMedicineType", method = RequestMethod.GET)
    public JsonResp selectMedicineType() {
        log.debug("selectMedicineType");

        try {
            List<DictMedicineType> dictList = dictMedicineTypeService.selectByMap(null);
            return JsonResp.ok(dictList);
        } catch (Exception e) {
            log.error("selectMedicineType failed", e);
            return JsonResp.fa(null);
        }
    }

    @RequestMapping(value = "/queryInspection", method = RequestMethod.GET)
    public JsonResp queryInspection() {
        log.debug("queryInspection");

        try {
            List<DictInspection> dictList = dictInspectionService.selectByMap(null);
            return JsonResp.ok(dictList);
        } catch (Exception e) {
            log.error("queryInspection failed", e);
            return JsonResp.fa(null);
        }
    }

    @RequestMapping(value = "/queryMedicine", method = RequestMethod.GET)
    public JsonResp queryMedicine() {
        log.debug("queryMedicine");

        try {
            List<DictMedicine> dictList = dictMedicineService.selectByMap(null);
            return JsonResp.ok(dictList);
        } catch (Exception e) {
            log.error("queryMedicine failed", e);
            return JsonResp.fa(null);
        }
    }

    @RequestMapping(value = "/queryOperation", method = RequestMethod.GET)
    public JsonResp queryOperation() {
        log.debug("queryOperation");

        try {
            List<DictOperation> dictList = dictOperationService.selectByMap(null);
            return JsonResp.ok(dictList);
        } catch (Exception e) {
            log.error("queryOperation failed", e);
            return JsonResp.fa(null);
        }
    }

    @RequestMapping(value = "/queryOperationType", method = RequestMethod.GET)
    public JsonResp queryOperationType() {
        log.debug("queryOperationType");

        try {
            List<DictOperationType> dictList = dictOperationTypeService.selectByMap(null);
            return JsonResp.ok(dictList);
        } catch (Exception e) {
            log.error("queryOperationType failed", e);
            return JsonResp.fa(null);
        }
    }

    @RequestMapping(value = "/queryMedicineUseType", method = RequestMethod.GET)
    public JsonResp queryMedicineUseType() {
        log.debug("queryMedicineUseType");

        try {
            List<DictMedicineUseType> dictList = dictMedicineUseTypeService.selectByMap(null);
            return JsonResp.ok(dictList);
        } catch (Exception e) {
            log.error("queryMedicineUseType failed", e);
            return JsonResp.fa(null);
        }
    }
}
